package com.spdzen.support;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.exception.ExceptionUtils;

public class RequestInfo implements Serializable {
	private static final long serialVersionUID = 4694405250122881508L;

	/**
	 * 开始时间，1970年到现在的毫秒数
	 */
	private long start;

	/**
	 * 执行时长，单位毫秒
	 */
	private long duration;

	/**
	 * 通过{@link javax.servlet.http.HttpServletRequest#getServletPath()}获取
	 */
	private String servletPath;

	/**
	 * {@link javax.servlet.http.HttpServletRequest#getParameterMap()}
	 * 获取到的参数JSON序列化
	 */
	private String parameters;

	/**
	 * 异常描述List， 格式为 {@link java.lang.Throwable#printStackTrace()}的值
	 */
	private List<String> exceptions = new ArrayList<String>();
	
	/**
	 * 响应状态
	 */
	private int responseStatus;

	/**
	 * 客户端IP
	 */
	private String clientIp;

	/**
	 * 浏览器信息
	 */
	private String userAgent;
	
	/**
	 * 是否微信浏览器
	 */
	private boolean weixinBrowser;

	/**
	 * SpringMVC控制器类名
	 */
	private String clazz;

	/**
	 * Request对应的SpringMVC控制器方法
	 */
	private String method;
	
	public boolean hasError() {
		return exceptions.size() > 0;
	}
	
	public void addException (Throwable e) {
		if(e != null) {
			this.exceptions.add(ExceptionUtils.getStackTrace(e));
		}
	}

	public long getStart() {
		return start;
	}

	public void setStart(long start) {
		this.start = start;
	}

	public long getDuration() {
		return duration;
	}

	public void setDuration(long duration) {
		this.duration = duration;
	}

	public List<String> getExceptions() {
		return exceptions;
	}

	public void addException(String exception) {
		if (exception != null && exception.length() > 0) {
			this.exceptions.add(exception);
		}
	}

	public String getServletPath() {
		return servletPath;
	}

	public void setServletPath(String servletPath) {
		this.servletPath = servletPath;
	}

	public String getParameters() {
		return parameters;
	}

	public void setParameters(String parameters) {
		this.parameters = parameters;
	}

	public String getClientIp() {
		return clientIp;
	}

	public void setClientIp(String clientIp) {
		this.clientIp = clientIp;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getUserAgent() {
		return userAgent;
	}

	public void setUserAgent(String userAgent) {
		this.userAgent = userAgent;
	}

	public String getClazz() {
		return clazz;
	}

	public void setClazz(String clazz) {
		this.clazz = clazz;
	}

	public boolean isWeixinBrowser() {
		return weixinBrowser;
	}

	public void setWeixinBrowser(boolean weixinBrowser) {
		this.weixinBrowser = weixinBrowser;
	}

	public int getResponseStatus() {
		return responseStatus;
	}

	public void setResponseStatus(int responseStatus) {
		this.responseStatus = responseStatus;
	}
}
